﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.Utils;
using Newtonsoft.Json;

namespace Ccit.Mgoa.Collaboration
{
    public partial class collaboration_type_edit : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hdTypeId.Value = (Request.QueryString["id"] != null) ? Request.QueryString["id"].ToString() : "";
                InitPage();
            }
        }

        private void InitPage()
        {
            string sTypeId = hdTypeId.Value;
            if (sTypeId != "")
            {
                CollaborateBLL oCollaborate=new CollaborateBLL();
                MsCollaborativeType msCollaborativeType = oCollaborate.GetCollaborativeTypeById(sTypeId);
                txtTypeName.Value = msCollaborativeType.TypeName;
                txtTypeDesc.Text = msCollaborativeType.TypeDesc.Replace("\r\n", "<br/>");
                hdManageRangeType.Value = msCollaborativeType.ManagementRange;
                hdManageRange.Value = msCollaborativeType.ManagementId;
                txtManageRange.Text = SysInterface.GetNameStrByIdStr(msCollaborativeType.ManagementId, msCollaborativeType.ManagementRange, "");
                hdPublishRangeType.Value = msCollaborativeType.PublishedRange;
                hdPublishRange.Value = msCollaborativeType.PublishedId;
                txtPublishRange.Text = SysInterface.GetNameStrByIdStr(msCollaborativeType.PublishedId, msCollaborativeType.PublishedRange, "");
            }
        }

        /// <summary>
        /// 保存协作类型信息
        /// </summary>
        /// <param name="sCollaboration"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string SaveCollaboration(string sCollaboration)
        {
            string sResult = "";
            MsCollaborativeType msCollaborativeType = (MsCollaborativeType)JavaScriptConvert.DeserializeObject(sCollaboration,typeof(MsCollaborativeType));
            CollaborateBLL oCollaborate = new CollaborateBLL();
            sResult = oCollaborate.SaveCollaboration(msCollaborativeType);
            return sResult;
        }
    }
}
